home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Fight / fight.jar / FightObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-16  |  7.9 KB  |  573 lines

  1. import java.util.Random;
  2.  
  3. public class FightObject {
  4.    final int STAND = 0;
  5.    final int WALK = 1;
  6.    final int JUMP = 2;
  7.    final int CROUCH = 3;
  8.    final int ATTACK = 4;
  9.    final int CROUCH_ATTACK = 5;
  10.    final int HIT = 6;
  11.    final int CROUCH_HIT = 7;
  12.    FightCanvas parent;
  13.    byte player = 0;
  14.    static Random rand = new Random();
  15.    // $FF: renamed from: x int
  16.    int field_0;
  17.    // $FF: renamed from: y int
  18.    int field_1;
  19.    int state;
  20.    int interval;
  21.    int walking;
  22.    int stop_walking;
  23.    int walk_state;
  24.    int stand_state;
  25.    boolean crouching;
  26.    boolean jump_up;
  27.    int jump_attack_state;
  28.    int jump_pos;
  29.    int attack_dur;
  30.    int attack_type;
  31.    int diff = 0;
  32.    boolean blocking;
  33.    boolean attacking = false;
  34.    public byte energy = 25;
  35.    public byte power = 3;
  36.    public byte speed = 3;
  37.    public byte jump = 10;
  38.    public int direct = 1;
  39.    int hit_dur;
  40.    boolean hit_jump;
  41.    // $FF: renamed from: id int
  42.    int field_2 = 0;
  43.    int id_e = 0;
  44.    int attack_no = 0;
  45.  
  46.    public FightObject(FightCanvas var1, int var2) {
  47.       this.parent = var1;
  48.       this.player = (byte)var2;
  49.       if (this.player == 1) {
  50.          this.direct = -1;
  51.       }
  52.  
  53.       this.diff = 0;
  54.       this.init();
  55.    }
  56.  
  57.    public void setSkills(byte[] var1) {
  58.       this.energy = var1[0];
  59.       this.power = var1[1];
  60.       this.speed = var1[2];
  61.       this.jump = var1[3];
  62.    }
  63.  
  64.    public void dead() {
  65.       this.state = 0;
  66.       this.jump();
  67.  
  68.       for(int var1 = 0; var1 < 8; ++var1) {
  69.          if (var1 == 5) {
  70.             this.hit();
  71.          }
  72.  
  73.          try {
  74.             Thread.sleep(100L);
  75.          } catch (Exception var3) {
  76.          }
  77.  
  78.          this.run();
  79.          if (this.player == 0) {
  80.             this.parent.playerSpr.setPosition(this.field_0, this.field_1 - 20 - this.jump_pos);
  81.          } else {
  82.             this.parent.enemySpr.setPosition(this.field_0, this.field_1 - 20 - this.jump_pos);
  83.          }
  84.  
  85.          this.parent.repaint();
  86.       }
  87.  
  88.    }
  89.  
  90.    public int rand(int var1) {
  91.       int var2 = rand.nextInt() % var1;
  92.       if (var2 < 0) {
  93.          var2 = -var2;
  94.       }
  95.  
  96.       return var2;
  97.    }
  98.  
  99.    public void cpuMove() {
  100.       if (!this.isHit()) {
  101.          switch (this.diff) {
  102.             case 0:
  103.                if (this.interval % 2 == 0) {
  104.                   return;
  105.                }
  106.                break;
  107.             case 1:
  108.                if (this.interval % 3 == 0) {
  109.                   return;
  110.                }
  111.          }
  112.  
  113.          if (this.parent.fightObject.field_0 > this.field_0 + Fight.bounds[this.id_e][2] - (48 - Fight.bounds[this.field_2][2]) + Fight.skills[this.field_2][2] * 3) {
  114.             if (this.crouching) {
  115.                this.crouchStart();
  116.             }
  117.  
  118.             switch (this.rand(7)) {
  119.                case 0:
  120.                   this.jump();
  121.                   this.stepRight();
  122.                   break;
  123.                case 1:
  124.                   this.stepRight();
  125.                   break;
  126.                case 2:
  127.                   this.jump();
  128.                   this.attack(1);
  129.                   break;
  130.                default:
  131.                   return;
  132.             }
  133.          }
  134.  
  135.          if (this.parent.fightObject.attacking) {
  136.             ++this.attack_no;
  137.             if (this.rand(3) != 1) {
  138.                if (this.rand(3) >= this.diff) {
  139.                   this.block();
  140.                }
  141.  
  142.                return;
  143.             }
  144.  
  145.             switch (this.rand(10)) {
  146.                case 2:
  147.                   this.crouchStart();
  148.                   break;
  149.                case 3:
  150.                   this.stepLeft();
  151.                   break;
  152.                case 4:
  153.                   this.attack(0);
  154.                   break;
  155.                case 5:
  156.                   this.attack(1);
  157.                   break;
  158.                default:
  159.                   return;
  160.             }
  161.          } else {
  162.             int var1 = this.rand(14);
  163.             switch (var1) {
  164.                case 0:
  165.                case 1:
  166.                case 2:
  167.                   if (this.crouching) {
  168.                      switch (this.rand(4)) {
  169.                         case 0:
  170.                            this.attack(0);
  171.                            return;
  172.                         case 1:
  173.                            this.attack(1);
  174.                            return;
  175.                         default:
  176.                            return;
  177.                      }
  178.                   } else {
  179.                      this.crouchStart();
  180.                      break;
  181.                   }
  182.                case 3:
  183.                   this.stepLeft();
  184.                   break;
  185.                case 4:
  186.                case 5:
  187.                   this.attack(0);
  188.                   break;
  189.                case 6:
  190.                case 7:
  191.                   this.attack(1);
  192.                   break;
  193.                case 8:
  194.                case 9:
  195.                   this.jump();
  196.                default:
  197.                   return;
  198.             }
  199.          }
  200.  
  201.       }
  202.    }
  203.  
  204.    public void init() {
  205.       this.state = 0;
  206.       if (this.player == 0) {
  207.          this.field_2 = Fight.players[0];
  208.          this.id_e = Fight.players[this.parent.level + 1];
  209.          this.field_0 = 50;
  210.          this.field_1 = 48;
  211.       } else {
  212.          this.field_2 = Fight.players[this.parent.level + 1];
  213.          this.id_e = Fight.players[0];
  214.          this.field_0 = 0;
  215.          this.field_1 = 48;
  216.       }
  217.  
  218.       this.walk_state = 0;
  219.       this.stand_state = 0;
  220.       this.stop_walking = 0;
  221.       this.jump_pos = 0;
  222.       this.blocking = false;
  223.       this.attacking = false;
  224.    }
  225.  
  226.    public boolean isHit() {
  227.       return this.state == 6 || this.state == 7;
  228.    }
  229.  
  230.    public void checkRange() {
  231.       if (this.player == 0 && this.field_0 < this.parent.enemySpr.getXPosition() + Fight.bounds[this.id_e][2] - (48 - Fight.bounds[this.field_2][2])) {
  232.          this.field_0 = this.parent.enemySpr.getXPosition() + Fight.bounds[this.id_e][2] - (48 - Fight.bounds[this.field_2][2]);
  233.       }
  234.  
  235.       if (this.player == 1 && this.field_0 > this.parent.playerSpr.getXPosition() - (Fight.bounds[this.id_e][2] - (48 - Fight.bounds[this.field_2][2]))) {
  236.          this.field_0 = this.parent.playerSpr.getXPosition() - (Fight.bounds[this.id_e][2] - (48 - Fight.bounds[this.field_2][2]));
  237.       }
  238.  
  239.       if (this.player == 0) {
  240.          if (this.field_0 < -20) {
  241.             this.field_0 = -20;
  242.          }
  243.  
  244.          if (this.field_0 > 50) {
  245.             this.field_0 = 50;
  246.          }
  247.       } else {
  248.          if (this.field_0 < 0) {
  249.             this.field_0 = 0;
  250.          }
  251.  
  252.          if (this.field_0 > 65) {
  253.             this.field_0 = 65;
  254.          }
  255.       }
  256.  
  257.    }
  258.  
  259.    static int abs(int var0) {
  260.       return var0 < 0 ? -var0 : var0;
  261.    }
  262.  
  263.    public void attack(int var1) {
  264.       switch (this.state) {
  265.          case 0:
  266.          case 1:
  267.             this.state = 4;
  268.             this.attack_dur = 2;
  269.             switch (var1) {
  270.                case 0:
  271.                   this.attack_type = 0;
  272.                   return;
  273.                case 1:
  274.                   this.attack_type = 1;
  275.                   return;
  276.                default:
  277.                   return;
  278.             }
  279.          case 2:
  280.             if (this.walking != 0) {
  281.                this.jump_attack_state = 1;
  282.             } else {
  283.                this.jump_attack_state = 2;
  284.             }
  285.             break;
  286.          case 3:
  287.             this.state = 5;
  288.             this.attack_dur = 3;
  289.             switch (var1) {
  290.                case 0:
  291.                   this.attack_type = 0;
  292.                   break;
  293.                case 1:
  294.                   this.attack_type = 1;
  295.             }
  296.       }
  297.  
  298.    }
  299.  
  300.    public void block() {
  301.       switch (this.state) {
  302.          case 0:
  303.          case 1:
  304.             this.attack_dur = 6;
  305.             this.state = 4;
  306.             this.attack_type = 2;
  307.          case 2:
  308.          default:
  309.             break;
  310.          case 3:
  311.             this.attack_dur = 6;
  312.             this.state = 5;
  313.             this.attack_type = 2;
  314.       }
  315.  
  316.    }
  317.  
  318.    public void hit() {
  319.       switch (this.state) {
  320.          case 0:
  321.          case 1:
  322.             this.state = 6;
  323.             this.hit_dur = 4;
  324.             break;
  325.          case 2:
  326.             this.hit_jump = true;
  327.             break;
  328.          case 3:
  329.             this.state = 7;
  330.             this.hit_dur = 5;
  331.       }
  332.  
  333.    }
  334.  
  335.    public void crouchStart() {
  336.       if (this.state != 2) {
  337.          if (this.crouching) {
  338.             this.state = 1;
  339.             this.crouching = false;
  340.          } else {
  341.             this.state = 3;
  342.             this.crouching = true;
  343.          }
  344.  
  345.       }
  346.    }
  347.  
  348.    public void stepLeft() {
  349.       this.walking = -1;
  350.       if (this.state == 2) {
  351.          this.walking = -3;
  352.       }
  353.  
  354.       this.walk_state = 1;
  355.       --this.stop_walking;
  356.    }
  357.  
  358.    public void stepRight() {
  359.       this.walking = 1;
  360.       if (this.state == 2) {
  361.          this.walking = 3;
  362.       }
  363.  
  364.       this.walk_state = 0;
  365.       --this.stop_walking;
  366.    }
  367.  
  368.    public void walkReset() {
  369.       if (this.crouching) {
  370.          this.state = 3;
  371.       } else if (this.walking == 0) {
  372.          this.state = 0;
  373.       } else {
  374.          this.state = 1;
  375.       }
  376.  
  377.       this.hit_jump = false;
  378.       this.stop_walking = 0;
  379.    }
  380.  
  381.    public void jump() {
  382.       switch (this.state) {
  383.          case 0:
  384.          case 1:
  385.          case 3:
  386.             this.jump_up = true;
  387.             this.jump_attack_state = 0;
  388.             this.state = 2;
  389.             this.crouching = false;
  390.             break;
  391.          case 2:
  392.          default:
  393.             this.jump_attack_state = 0;
  394.       }
  395.  
  396.    }
  397.  
  398.    public void run() {
  399.       ++this.interval;
  400.       switch (this.state) {
  401.          case 0:
  402.          case 1:
  403.             if (this.walking != 0) {
  404.                this.state = 1;
  405.                ++this.walk_state;
  406.                if (this.stop_walking >= 0 && (this.walk_state + 1) % 2 == 0) {
  407.                   this.walking = 0;
  408.                }
  409.  
  410.                this.field_0 += this.walking * this.speed;
  411.                this.checkRange();
  412.             } else {
  413.                this.state = 0;
  414.                if (this.interval % 2 == 0) {
  415.                   ++this.stand_state;
  416.                }
  417.             }
  418.             break;
  419.          case 2:
  420.             if (this.hit_jump) {
  421.                this.field_0 += this.speed * this.direct;
  422.             }
  423.  
  424.             if (this.jump_up) {
  425.                this.jump_pos += this.jump;
  426.                if (this.jump_pos >= 2 * this.jump) {
  427.                   this.jump_up = false;
  428.                   ++this.jump_pos;
  429.                }
  430.             } else {
  431.                this.jump_pos -= this.jump;
  432.                if (this.jump_pos <= 0) {
  433.                   this.jump_pos = 0;
  434.                   this.walking = 0;
  435.                   this.walkReset();
  436.                }
  437.             }
  438.  
  439.             this.field_0 += this.walking * this.speed;
  440.          case 3:
  441.          default:
  442.             break;
  443.          case 4:
  444.             --this.attack_dur;
  445.             if (this.attack_dur == 0) {
  446.                this.walkReset();
  447.             }
  448.             break;
  449.          case 5:
  450.             --this.attack_dur;
  451.             if (this.attack_dur == 0) {
  452.                this.walkReset();
  453.             }
  454.             break;
  455.          case 6:
  456.             this.field_0 += this.speed * this.direct;
  457.             --this.hit_dur;
  458.             if (this.hit_dur == 0) {
  459.                this.walkReset();
  460.             }
  461.             break;
  462.          case 7:
  463.             --this.hit_dur;
  464.             this.field_0 += this.speed * this.direct;
  465.             if (this.hit_dur == 0) {
  466.                this.walkReset();
  467.             }
  468.       }
  469.  
  470.       this.checkRange();
  471.       this.attacking = false;
  472.       if (this.state == 4 || this.state == 5) {
  473.          if (this.attack_type == 2) {
  474.             this.blocking = true;
  475.          } else {
  476.             this.blocking = false;
  477.             this.attacking = true;
  478.          }
  479.       }
  480.  
  481.       if (this.jump_attack_state > 0) {
  482.          this.attacking = true;
  483.       }
  484.  
  485.       this.setPlayerFrame();
  486.    }
  487.  
  488.    public void setPlayerFrame() {
  489.       int var1 = 0;
  490.       byte var2 = 0;
  491.       switch (this.state) {
  492.          case 0:
  493.             var1 = this.stand_state % 2;
  494.             var2 = 0;
  495.             break;
  496.          case 1:
  497.             var1 = this.walk_state % 2 + 2;
  498.             var2 = 0;
  499.             break;
  500.          case 2:
  501.             if (this.hit_jump) {
  502.                var1 = 7;
  503.             } else {
  504.                if (this.jump_up) {
  505.                   switch (this.jump_attack_state) {
  506.                      case 2:
  507.                         var1 = 14;
  508.                         break;
  509.                      default:
  510.                         var1 = 12;
  511.                   }
  512.                } else {
  513.                   switch (this.jump_attack_state) {
  514.                      case 0:
  515.                         var1 = 13;
  516.                         break;
  517.                      case 1:
  518.                         var1 = 14;
  519.                         break;
  520.                      case 2:
  521.                         var1 = 15;
  522.                   }
  523.                }
  524.  
  525.                var2 = 0;
  526.             }
  527.             break;
  528.          case 3:
  529.             var2 = 3;
  530.             var1 = 8;
  531.             break;
  532.          case 4:
  533.             if (this.attack_type == 0) {
  534.                var2 = 1;
  535.             }
  536.  
  537.             if (this.attack_type == 1) {
  538.                var2 = 2;
  539.             }
  540.  
  541.             var1 = this.attack_type + 4;
  542.             break;
  543.          case 5:
  544.             if (this.attack_type == 0) {
  545.                var2 = 4;
  546.             }
  547.  
  548.             if (this.attack_type == 1) {
  549.                var2 = 5;
  550.             }
  551.  
  552.             var1 = this.attack_type + 9;
  553.             break;
  554.          case 6:
  555.             var2 = 0;
  556.             var1 = 7;
  557.             break;
  558.          case 7:
  559.             var2 = 3;
  560.             var1 = 12;
  561.       }
  562.  
  563.       if (this.player == 0) {
  564.          this.parent.playerSpr.setFrame(var1);
  565.          this.parent.playerSpr.setCollisionRectangle(48 - Fight.bounds[this.field_2][var2 + 2], Fight.sizes[this.field_2] - Fight.bounds[this.field_2][var2 / 3], Fight.bounds[this.field_2][var2 + 2], Fight.bounds[this.field_2][var2 / 3]);
  566.       } else {
  567.          this.parent.enemySpr.setFrame(var1);
  568.          this.parent.enemySpr.setCollisionRectangle(0, Fight.sizes[this.field_2] - Fight.bounds[this.field_2][var2 / 3], Fight.bounds[this.field_2][var2 + 2], Fight.bounds[this.field_2][var2 / 3]);
  569.       }
  570.  
  571.    }
  572. }
  573.